﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JsonEditor.Common
{
    public class CPropertyCollection : Collection<CProperty>, ICustomTypeDescriptor
    {

        public void Add(CProperty value)
        {

            base.Add(new CProperty(value.Name, value));

        }

        #region "TypeDescriptor"



        public String GetClassName()
        {

            return TypeDescriptor.GetClassName(this, true);

        }



        public AttributeCollection GetAttributes()
        {

            return TypeDescriptor.GetAttributes(this, true);

        }



        public String GetComponentName()
        {

            return TypeDescriptor.GetComponentName(this, true);

        }



        public TypeConverter GetConverter()
        {

            return TypeDescriptor.GetConverter(this, true);

        }



        public EventDescriptor GetDefaultEvent()
        {

            return TypeDescriptor.GetDefaultEvent(this, true);

        }



        public PropertyDescriptor GetDefaultProperty()
        {

            return TypeDescriptor.GetDefaultProperty(this, true);

        }



        public object GetEditor(Type editorBaseType)
        {

            return TypeDescriptor.GetEditor(this, editorBaseType, true);

        }



        public EventDescriptorCollection GetEvents(Attribute[] attributes)
        {

            return TypeDescriptor.GetEvents(this, attributes, true);

        }



        public EventDescriptorCollection GetEvents()
        {

            return TypeDescriptor.GetEvents(this, true);

        }



        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {

            PropertyDescriptor[] propDes = new PropertyDescriptor[this.Count];

            for (int i = 0; i < this.Count; i++)
            {

                CProperty prop = (CProperty)this[i];

                propDes[i] = new CPropertyDescriptor(ref prop, attributes);

            }

            return new PropertyDescriptorCollection(propDes);

        }



        public PropertyDescriptorCollection GetProperties()
        {

            return TypeDescriptor.GetProperties(this, true);

        }



        public object GetPropertyOwner(PropertyDescriptor pd)
        {

            return this;

        }

        #endregion

    }
}
